/**
 * 对象相关函数
 * @exports CFObject
 * @constructor CFObject
 * @description 调用方法：$cf.CFObject.函数名称
 */

class CFObject {
  /**
   * 对象或数组深度拷贝
   * @param {Obeject|Array} obj 原始对象
   * @returns {Object|Array} 深度拷贝后的对象
   * @example
   * var obj = {x: 1, y: function() {}};
   * $cf.CFObject.deepClone(obj); // {x: 1, y: function() {}}
   */
  deepClone(obj) {
    if (typeof obj !== 'object' || !obj) {
      return obj;
    }
    let objClone = Array.isArray(obj) ? [] : {};
    for (let key in obj) {
      if (Object.hasOwnProperty.call(obj, key)) {
        if (obj[key] && typeof obj[key] === 'object') {
          objClone[key] = this.deepClone(obj[key]);
        } else {
          objClone[key] = obj[key];
        }
      }
    }
    return objClone;
  }
}

export default CFObject;
